<template>
  <div>
    <hy-order-descriptions :orderId='orderId' v-if='loaded'></hy-order-descriptions>
    <a-divider orientation='left'>发货信息</a-divider>
    <f-table ref='orderDrugs' rowKey='orderDetailsId' :showTotal='true' :tableColumns='orderDetailsColumns' :scroll='{x:true}' handler='hyOrderReturnHandler' :pageSize='80' :operator='operator' :params='queryParam' :api='api.hyOrderDetails' :autoLoad='false' :showPagination='false' :multiple='false'>
     
      <span slot='action' slot-scope='text, record, index' v-if='record.rowIndex!="合计"'>
          <a-button @click='calculateOrder(record)' type='primary' size='small'>核算</a-button>
      </span>

      <span slot='costPrice' slot-scope='text, record, index' v-if='record.rowIndex!="合计"'>
          <span v-if='show'>{{ text }}</span>
          <a-icon v-if='!show' type='eye-invisible' />
      </span>
      <span slot='costAmount' slot-scope='text, record, index'>
          <span v-if='show'>{{ text }}</span>
          <a-icon v-if='!show' type='eye-invisible' />
      </span>
    </f-table>
    <hy-order-calcuate-drawer ref='calcuateDrawer'></hy-order-calcuate-drawer>
  </div>

</template>

<script>
import api from "../../../js/api"
import ProcessImage from "../../../../flowable/process/process_image"
import HyOrderCalcuateDrawer from "../../../order/caclulate/hy_order_calculate_drawer"
import { commonMixins } from "@/core/mixins/commonMixins"
import HyOrderDescriptions from "@/views/module/haiying/order/details/hyorder_descriptions"

export default {
  name: "HyOrderApprove",
  components: { HyOrderDescriptions, HyOrderCalcuateDrawer, ProcessImage },
  mixins: [commonMixins],
  props:{
    applyMode:{
      type: Boolean,
      default: true
    }
  },
  data() {
    let me = this
    //操作按钮
    let operator = []
    let isCw = this.$store.state.user.roleInfo.isCw
    if (isCw) {
      operator.push({
        name: this.show ? "隐藏成本" : "显示成本",
        that: this,
        handler: () => {
          this.show = !this.show
        }
      })
    }
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      processImageVisible: false,
      orderId: null,
      loaded: false,
      show: false,
      order: {},
      formItem: {},
      orderForm: {},
      operator: operator,
      orderDetailsColumns: [],
      columns2: [],
      customHeaderCell: (column) => {
        return {
          style: {
            "backgroundColor": "#722ED1",
            color: "red"
          }
        }
      }
    }
  },
  created() {
  },
  computed: {
    title: function() {
      return this.saleType == "CHC" ? "退货" : "补货"
    }
  },
  methods: {
    getFormItem() {
      return {
        returnId: "",
        saleNum: 0,
        noReturnNum: 0,
        noReturnAmount: "",
        sendDate: "",
        hkImage: []
      }
    },
    //核算订单
    calculateOrder(record) {
      this.http.confirm(this, {
        content: "确认重新核算订单?",
        url: api.hyOrderDetails.calculate,
        data: {
          orderDetailsId: record.orderDetailsId
        },
        success: (me, data) => {
          this.$refs.orderDrugs.refresh()
        }
      })
    },
    getOrderDetailsColumns(data) {
      let isCw = this.$store.state.user.roleInfo.isCw
      let sendType = data.sendType
      let isZbj = false
      if (sendType == 3) {
        isZbj = true
      }
      let orderDetailsColumns = [
        {
          title: "序号",
          width: "60px",
          align: "center",
          dataIndex: "rowIndex",
          customRender: function(text, record, index) {
            return (record.rowIndex !== "合计") ? (parseInt(index) + 1) : record.rowIndex
          }
        }, {
          title: "操作",
          align: "center",
          dataIndex: "action",
          hidden:!this.applyMode,
          width: "80px",
          scopedSlots: { customRender: "action" }
        }, {
          title: "商品名称",
          align: "center",
          width: "180px",
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "批号",
          align: "center",
          width: "90px",
          dataIndex: "drugLotNo"
        }, {
          title: "规格",
          align: "center",
          ellipsis: true,
          width: "140px",
          dataIndex: "drugsSpec"
        }, {
          title: "销售单价",
          align: "center",
          width: "80px",
          dataIndex: "salePrice",
          customCell: this.renderTdBackground
        }, , {
          title: "数量",
          align: "center",
          width: "80px",
          needTotal: true,
          dataIndex: "saleNum"
        }, {
          title: "销售金额",
          align: "center",
          needTotal: true,
          width: "90px",
          dataIndex: "saleAmount"
        }, {
          title: "成本单价",
          align: "center",
          width: "80px",
          hidden: !isCw,
          dataIndex: "costPrice",
          scopedSlots: { customRender: "costPrice" }
        }, {
          title: "成本金额",
          align: "center",
          width: "80px",
          needTotal: true,
          hidden: !isCw,
          dataIndex: "costAmount",
          scopedSlots: { customRender: "costAmount" }
        }, {
          title: "底价",
          align: "center",
          width: "80px",
          needTotal: true,
          hidden: !isZbj,
          dataIndex: "customFloorAmount"
        }, {
          title: "税金",
          align: "center",
          width: "80px",
          needTotal: true,
          hidden: !isZbj,
          dataIndex: "customGapUpAmount"
        }, {
          title: "资保金金额",
          align: "center",
          width: "80px",
          hidden: !isZbj,
          needTotal: true,
          dataIndex: "customBond"
        }
      ]
      return orderDetailsColumns
    },
    setData(data) {
      if (data && data.orderId) {
        this.orderId = data.orderId
        this.loaded = true
        this.queryParam.orderId = data.orderId
        this.orderDetailsColumns = this.getOrderDetailsColumns(data)
        this.$refs["orderDrugs"].refresh(false)
      }
    },
    renderTdBackground(record, flag) {
      if (record.costPrice > record.salePrice) {
        return {
          style: {
            "background-color": "rgb(255,150,150)"
          }
        }
      }
    },
    processImg(order) {
      this.processInstanceId = order.processInstanceId
      this.processImageVisible = true
    }
  }
}
</script>
<style lang='less'>


</style>